package com.joca.scheduling.pages;

import org.apache.tapestry5.Block;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.joca.scheduling.database.UserData;
import com.joca.scheduling.entities.Role;
import com.joca.scheduling.entities.User;
import com.joca.scheduling.hibernateservices.UserServiceHibernate;
import com.joca.scheduling.service.IUserServiceHibernate;

public class Registration {

	@SessionState(create = false)
	@Property
	private User user;
	private boolean userExists;
	@Property
	@Persist("flash")
	private User userr;

	@Inject
	private IUserServiceHibernate iush;

	Object onActivate() {
		// ID = 3;
		if (!userExists)
			return Index.class;
		if (user.getRole() == Role.Professor) {
			return null;
		}
		return Index.class;
	}

	// @Persist
	// private int ID;

	Object onSuccess() {
		// userr.setUserID(ID);
		// ID++;
		// UserData.getInstance().addUser(userr);
		System.out.println(userr.getName() + " " + userr.getSurname());
		UserServiceHibernate.getUserServiceHibernate().addUser(userr);
		// iush.addUser(userr);
		User us = UserServiceHibernate.getUserServiceHibernate().getUserByID(2);
		// User us = iush.getUserByID(3);
		System.out.println(us.getName() + " " + us.getSurname());
		return null;
	}

}
